﻿using MCPlatform.MotionLib.Base;
using MCPlatform.MotionLib.Base.AssitantClass;
using MCPlatform.UI.Controls.AssistantMethods.StaticMethods;
using Panuon.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCPlatform.UI.Controls.Models
{
    public class ImpMotionModel : NotifyPropertyChangedBase, INameProvider
    {

        #region Properties

        /// <summary>
        /// 插补对象
        /// </summary>
        public IImputation? ImputationEntity { get => _ImputationEntity; set => Set(ref _ImputationEntity, value); }
        private IImputation? _ImputationEntity;


        /// <summary>
        /// 插补对象名称
        /// </summary>
        public string ControlName
        {
            get => _ControlName;
            set
            {
                Set(ref _ControlName, value);

            }
        }

        private string _ControlName = string.Empty;


        public double XAxiPos
        {
            get => _XAxiPos;
            set
            {
                Set(ref _XAxiPos, value);

            }
        }

        private double _XAxiPos = 0.0;


        public double YAxiPos
        {
            get => _YAxiPos;
            set
            {
                Set(ref _YAxiPos, value);

            }
        }

        private double _YAxiPos = 0.0;


        public double ZAxiPos
        {
            get => _ZAxiPos;
            set
            {
                Set(ref _ZAxiPos, value);

            }
        }

        private double _ZAxiPos = 0.0;

        public double UAxiPos
        {
            get => _UAxiPos;
            set
            {
                Set(ref _UAxiPos, value);

            }
        }

        private double _UAxiPos = 0.0;


        public double VAxiPos
        {
            get => _VAxiPos;
            set
            {
                Set(ref _VAxiPos, value);

            }
        }

        private double _VAxiPos = 0.0;



        public double WAxiPos
        {
            get => _WAxiPos;
            set
            {
                Set(ref _WAxiPos, value);

            }
        }

        private double _WAxiPos = 0.0;


        /// <summary>
        /// 坐标系速度
        /// </summary>
        public double ActualVelocity
        {
            get => _ActualVelocity;
            set
            {
                Set(ref _ActualVelocity, value);

            }
        }

        private double _ActualVelocity = 0.0;


        /// <summary>
        /// 设置速度
        /// </summary>
        public double SetVelocity
        {
            get => _SetVelocity;
            set
            {
                Set(ref _SetVelocity, value);

            }
        }

        private double _SetVelocity = 5;

        /// <summary>
        /// 坐标系忙
        /// </summary>
        public bool IsImpBusy
        {
            get => _IsImpBusy;
            set
            {
                Set(ref _IsImpBusy, value);

            }
        }

        private bool _IsImpBusy;


        /// <summary>
        /// 坐标系插补完成
        /// </summary>
        public bool IsImpDone
        {
            get => _IsImpDone;
            set
            {
                Set(ref _IsImpDone, value);

            }
        }
            
        private bool _IsImpDone;

        /// <summary>
        /// 坐标系空闲
        /// </summary>
        public bool IsImpIdle
        {
            get => _IsImpIdle;
            set
            {
                Set(ref _IsImpIdle, value);

            }
        }

        private bool _IsImpIdle;

        /// <summary>
        /// 坐标系暂停
        /// </summary>
        public bool IsImpPause
        {
            get => _IsImpPause;
            set
            {
                Set(ref _IsImpPause, value);

            }
        }

        private bool _IsImpPause;

        /// <summary>
        /// 坐标系有轴报警
        /// </summary>
        public bool IsImpError
        {
            get => _IsImpError;
            set
            {
                Set(ref _IsImpError, value);

            }
        }

        private bool _IsImpError;

        /// <summary>
        /// 坐标系轴已耦合
        /// </summary>
        public bool IsImpGear
        {
            get => _IsImpGear;
            set
            {
                Set(ref _IsImpGear, value);

            }
        }

        private bool _IsImpGear;

        public double[] TargetPosition
        {
            get 
            {
                List<double> position = new List<double>();
                if (ImputationEntity!=null && ImputationEntity?.ImputationConfig!=null)
                {
                    if (ImputationEntity.ImputationConfig.XAxisNo>=0)
                    {
                        position.Add(XTargetPositon);
                    }

                    if (ImputationEntity.ImputationConfig.YAxisNo >= 0)
                    {
                        position.Add(YTargetPositon);
                    }

                    if (ImputationEntity.ImputationConfig.ZAxisNo >= 0)
                    {
                        position.Add(ZTargetPositon);
                    }

                    if (ImputationEntity.ImputationConfig.UAxisNo >= 0)
                    {
                        position.Add(UTargetPositon);
                    }
                   

                    if (ImputationEntity.ImputationConfig.VAxisNo >= 0)
                    {
                        position.Add(VTargetPositon);
                    }
                   

                    if (ImputationEntity.ImputationConfig.WAxisNo >= 0)
                    {
                        position.Add(WTargetPositon);
                    }
                }
                
                return position.ToArray();
            }
            set { }
        }

        public double XTargetPositon
        {
            get => _XTargetPositon;
            set => Set(ref _XTargetPositon, value);
        }
        private double _XTargetPositon;


        public double YTargetPositon
        {
            get => _YTargetPositon;
            set => Set(ref _YTargetPositon, value);
        }
        private double _YTargetPositon;


        public double ZTargetPositon
        {
            get => _ZTargetPositon;
            set => Set(ref _ZTargetPositon, value);
        }
        private double _ZTargetPositon;


        public double UTargetPositon
        {
            get => _UTargetPositon;
            set => Set(ref _UTargetPositon, value);
        }
        private double _UTargetPositon;


        public double VTargetPositon
        {
            get => _VTargetPositon;
            set => Set(ref _VTargetPositon, value);
        }
        private double _VTargetPositon;


        public double WTargetPositon
        {
            get => _WTargetPositon;
            set => Set(ref _WTargetPositon, value);
        }
        private double _WTargetPositon;


        public double[] CenterPosition
        {
            get
            {
                List<double> position = new List<double>();
                if (ImputationEntity != null && ImputationEntity?.ImputationConfig != null)
                {
                    if (ImputationEntity.ImputationConfig.XAxisNo >= 0)
                    {
                        position.Add(XCenterPositon);
                    }

                    if (ImputationEntity.ImputationConfig.YAxisNo >= 0)
                    {
                        position.Add(YCenterPositon);
                    }

                    if (ImputationEntity.ImputationConfig.ZAxisNo >= 0)
                    {
                        position.Add(ZCenterPositon);
                    }

                    if (ImputationEntity.ImputationConfig.UAxisNo >= 0)
                    {
                        position.Add(UCenterPositon);
                    }
                    else
                    {
                        position.Add(0);
                    }

                    if (ImputationEntity.ImputationConfig.VAxisNo >= 0)
                    {
                        position.Add(VCenterPositon);
                    }
                    else
                    {
                        position.Add(0);
                    }

                    if (ImputationEntity.ImputationConfig.WAxisNo >= 0)
                    {
                        position.Add(WCenterPositon);
                    }
                }

                return position.ToArray();
            }
            set { }
        }


        public double XCenterPositon
        {
            get => _XCenterPositon;
            set => Set(ref _XCenterPositon, value);
        }
        private double _XCenterPositon;


        public double YCenterPositon
        {
            get => _YCenterPositon;
            set => Set(ref _YCenterPositon, value);
        }
        private double _YCenterPositon;


        public double ZCenterPositon
        {
            get => _ZCenterPositon;
            set => Set(ref _ZCenterPositon, value);
        }
        private double _ZCenterPositon;


        public double UCenterPositon
        {
            get => _UCenterPositon;
            set => Set(ref _UCenterPositon, value);
        }
        private double _UCenterPositon;


        public double VCenterPositon
        {
            get => _VCenterPositon;
            set => Set(ref _VCenterPositon, value);
        }
        private double _VCenterPositon;


        public double WCenterPositon
        {
            get => _WCenterPositon;
            set => Set(ref _WCenterPositon, value);
        }
        private double _WCenterPositon;



        public double Radius
        {
            get => _Radius;
            set => Set(ref _Radius, value);
        }
        private double _Radius;


        public ushort ArcDir
        {
            get => _ArcDir;
            set => Set(ref _ArcDir, value);
        }
        private ushort _ArcDir = 1;


        public ushort Circle
        {
            get => _Circle;
            set => Set(ref _Circle, value);
        }
        private ushort _Circle;


        public double Major
        {
            get => _Major;
            set => Set(ref _Major, value);
        }
        private double _Major;


        public double Minor
        {
            get => _Major;
            set => Set(ref _Minor, value);
        }
        private double _Minor;


        public bool IsAbs
        {
            get => _IsAbs;
            set => Set(ref _IsAbs, value);
        }
        private bool _IsAbs = false;






        #endregion



        #region Methods

        public void Mapping()
        {
            if (ImputationEntity is null) { return; }
            CommonUse.AutoMapProperties(ImputationEntity, this);
        }

        #endregion

       



    }
}
